package com.bjsxt.car.users.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.car.common.util.PageInfoUtil;
import com.bjsxt.car.users.dao.IARoleDao;
import com.bjsxt.car.users.dao.ICClientDao;
import com.bjsxt.car.users.pojo.AAdmins;
import com.bjsxt.car.users.pojo.ARole;
import com.bjsxt.car.users.pojo.CClient;
import com.bjsxt.car.users.service.IUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 用户Service的实现类
 * 
 * 当你写注解的时候,一定得想一想想一想,
 * 有木有告诉Spring哪些包下面的哪类里面的注解要识别
 * 扫描
 * 
 * @author XuGuoQing07
 *
 */
@Service("usersService")
public class UserServiceImpl implements IUserService
{
	/*
	 * 為 dao 賦值
	 * 当写上resource的时候,想一想想一想,有木有一个叫id=adminsDao的bean
	 * 木有的,然后使用 Mapper 代理,
	 * session.getMapper();
	 * 配一個 DAO 的扫描类
	 */
	@Resource
	private ICClientDao clientDao;
	@Resource
	private IARoleDao roleDao;
	
	@Override
	public JSONObject saveOneClientService(CClient client)
	{
		JSONObject dataJSON = new JSONObject();
		JSONObject resultJSON = new JSONObject();
		int res = this.clientDao.save(client);
		
		if(res > 0){
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			/* 存储的data也是一个json对象 */

			/*
			 * 成功 
			 *  res:执行此SQL语句对数据库影响的条数;
			 * */
			dataJSON.put("effect", res);
			dataJSON.put("id", client.getId());
			resultJSON.put("data", dataJSON);
			
		}else{
			/*失敗*/
			resultJSON.put("code", "1");
			resultJSON.put("info", "失敗");
		}
		return resultJSON;
	}

	@Override
	public CClient findOneClientService(Map<String, Object> condMap)
	{
		
		return this.clientDao.findOne(condMap);
	}
}
